<?php
class DictionaryListAction extends CommonAction {
	public function del($id) {
		$result = false;
		$dictList = M ( "DictionaryList" );
		$result = $dictList->Where ( 'id=' . $id )->delete ();
		if ($result == false) {
			echo json_encode ( array (
					'msg' => '删除出错！' 
			) );
		} else {
			echo json_encode ( array (
					'success' => true 
			) );
		}
	}
	public function save($id) {
		$result = false;
		$dictList = M ( "DictionaryList" );
		$data ['firstname'] = $_REQUEST ['firstname'];
		$data ['lastname'] = $_REQUEST ['lastname'];
		$data ['phone'] = $_REQUEST ['phone'];
		$data ['email'] = $_REQUEST ['email'];
		$result = $dictList->where ( 'id=' . $_REQUEST ['id'] )->save ( $data );
		if ($result == true) {
			echo json_encode ( array (
					'success' => true 
			) );
		} else {
			echo json_encode ( array (
					'msg' => '更新出错！' 
			));
		}
	}
	public function add() {
		$result = false;
		$dictList = M ( "DictionaryList" );
		$data ['firstname'] = $_REQUEST ['firstname'];
		$data ['lastname'] = $_REQUEST ['lastname'];
		$data ['phone'] = $_REQUEST ['phone'];
		$data ['email'] = $_REQUEST ['email'];
		$result = $dictList->add ( $data );
		if ($result == true) {
			echo json_encode ( array (
					'success' => true 
			) );
		} else {
			echo json_encode ( array (
					'msg' => '添加出错！' 
			) );
		}
	}
	
	public function read() {
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$dictId =  $_POST ['PARENT_ID'] ;
		$DictionaryList = M ( "DictionaryList" );
		if($dictId != ""){
			$total = $DictionaryList->where("ITEM_FLID={$dictId}")->count (); // 计算总数
		}else{
			$total = $DictionaryList->count (); // 计算总数
		}
		$dictionaryListArr = array ();
		if($dictId != ""){
			$dictionaryListArr = $DictionaryList->where("ITEM_FLID={$dictId}")->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		}else{
			$dictionaryListArr = $DictionaryList ->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		}
		$json = '{"total":' . $total . ',"rows":' . json_encode ( $dictionaryListArr ) . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
	

}
?>
